require 'sinatra/base'
require 'json'
require 'data_mapper'
require 'warden'

require './models/admin'

class WMSAdministrative < Sinatra::Application
    get '/' do
    	# admin dashboard will be here.
    	# render that sonnuvagun!
    	erb: "views/admin.erb"
    end

    get '/users/:id' do
        # return user information here
        User.first(:id=>Integer(params[:id])).to_json
    end

    put '/users/:id' do
        u = User.first(:id=>Integer(params[:id]))
        u.update(params)
    end

    ## ITEM ROUTES
    
    get '/items/:id' do
        # get the item by this id
        return Item.first(:id => Integer(params[:id])).to_json
    end

    put '/items/:id' do
        i = Item.first(:id=>Integer(params[:id]))
        i.update(params)
    end

    post '/items/find?' do
        query = {}
        #TODO: flesh this out
        # params: {"date": "2013-03-05", "name": "dog"}
        return Response.new(Item.get(query)).to_json
    end

    delete '/items/:id' do
        item = Item.first(:id => params[:id])
        item.destroy!
    end
end

#thin start -e production -p 3030 -d

## Server 2 (port 3040, production environment,"MY_PID.pid" pid file, deattached)

# thin start -e production -p 3040 -P MY_PID.pid -d
